/*
 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     bstefanescu
 */
package org.nuxeo.gwt.habyt.templates.client.bindings;

import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.DockPanel.DockLayoutConstant;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant;

/**
 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
 * 
 */
public class LayoutHelper {

    public static VerticalAlignmentConstant getVAlign(String valign) {
        if (HasVerticalAlignment.ALIGN_TOP.getVerticalAlignString().equals(
                valign)) {
            return HasVerticalAlignment.ALIGN_TOP;
        } else if (HasVerticalAlignment.ALIGN_MIDDLE.getVerticalAlignString().equals(
                valign)) {
            return HasVerticalAlignment.ALIGN_MIDDLE;
        } else if (HasVerticalAlignment.ALIGN_BOTTOM.getVerticalAlignString().equals(
                valign)) {
            return HasVerticalAlignment.ALIGN_BOTTOM;
        } else {
            return HasVerticalAlignment.ALIGN_TOP;
        }
    }

    public static HorizontalAlignmentConstant getHAlign(String halign) {
        if (HasHorizontalAlignment.ALIGN_LEFT.getTextAlignString().equals(
                halign)) {
            return HasHorizontalAlignment.ALIGN_LEFT;
        } else if (HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString().equals(
                halign)) {
            return HasHorizontalAlignment.ALIGN_CENTER;
        } else if (HasHorizontalAlignment.ALIGN_RIGHT.getTextAlignString().equals(
                halign)) {
            return HasHorizontalAlignment.ALIGN_RIGHT;
        } else {
            return HasHorizontalAlignment.ALIGN_LEFT;
        }
    }

    public static DockLayoutConstant getDockAlign(String align) {
        if ("west".equals(align)) {
            return DockPanel.WEST;
        } else if ("north".equals(align)) {
            return DockPanel.NORTH;
        }
        if ("east".equals(align)) {
            return DockPanel.EAST;
        }
        if ("south".equals(align)) {
            return DockPanel.SOUTH;
        } else {
            return DockPanel.CENTER;
        }
    }

}
